package com.wei.czz.common.enums.admin.user;

import com.wei.czz.common.dto.common.NameValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wyw
 * date: 2024-06-10 11:11:59
 * className: LoginChannelEnum 请求渠道枚举类
 * version: 1.0
 * description:
 */
@Getter
@AllArgsConstructor
public enum RequestChannelEnum {

    WEB(0, "web", "浏览器"),


    UNKNOWN(9999, "unknown", "未知来源")

    ;

    /**
     * 值
     */
    private final Integer value;

    /**
     * 名称
     */
    private final String name;

    /**
     * 昵称
     */
    private final String nickName;

    /**
     * 获取请求渠道枚举对象
     * @param name 名称
     * @return 请求渠道枚举对象
     */
    public static RequestChannelEnum get(String name) {
        for (RequestChannelEnum requestChannelEnum : values()) {
            if (requestChannelEnum.name.equals(name)) {
                return requestChannelEnum;
            }
        }
        return null;
    }

    /**
     * 获取名称
     * @param value 值
     * @return 名称
     */
    public static String getName(Integer value) {
        for (RequestChannelEnum requestChannelEnum : values()) {
            if (requestChannelEnum.value.equals(value)) {
                return requestChannelEnum.name;
            }
        }
        return "";
    }

    /**
     * 获取昵称
     * @param value 值
     * @return 名称
     */
    public static String getNickName(Integer value) {
        for (RequestChannelEnum requestChannelEnum : values()) {
            if (requestChannelEnum.value.equals(value)) {
                return requestChannelEnum.nickName;
            }
        }
        return "";
    }

    /**
     * 获取枚举列表
     */
    public static List<NameValue<Integer>> getList() {
        return Stream.of(values())
                .map(loginChannelEnum -> new NameValue<>(loginChannelEnum.nickName, loginChannelEnum.value))
                .collect(Collectors.toList());
    }

}
